home *** CD-ROM | disk | FTP | other *** search
- Short: MD5-based Random Number Generator (PPC+68k)
- Author: Rich Skrenta, Andreas R. Kleinert (port and sample program)
- Uploader: info@ar-kleinert.de
- Type: dev/c
-
- *************************************************************************
-
- After becoming frustrated with the lack of a standalone, portable,
- decent random number generator, I decided to make one based on a
- cryptographic one-way hash function. I chose MD5 since it is fast
- and free source was readily available. More cryptographically
- secure hash functions are available (e.g. SHA-1), but for the
- purposes of a rand/random/erand48 replacement, MD5 should be more
- than sufficient.
-
- MD5 takes an arbitrary amount of input and yields a 16 byte hash.
- This RNG continually MD5's a 16 byte digest, and uses the bottom N
- bits as the random number yielded, where N is just large enough to
- include the largest random number desired.
-
- To yield a random number between 0 and r:
-
- create mask which has enough bits to include all of r
- (for example, if r is 100, mask would be 0x7F)
-
- do {
- digest = MD5(digest)
- number = digest & mask
- } while (number > r)
-
- The digest should be loaded and saved to a disk file between
- invocations of a program using the RNG.
-
- Random functions appear after the included MD5 code.
-
- Send comments to: skrenta@pbm.com (Rich Skrenta)
-
- *************************************************************************
-
- The Amiga 68k/PPC version comes with both, makefiles for 68k and PPC,
- and test programs for both CPUs.
-
- A few changes had to be made for the Amiga port (#ifdef AMIGA) - and
- since this random number generator has a "brain", the most important
- change perhaps was, that the location of this brain now is "s:randseed".
-
- In case you want to run multiple copies of it, you'll perhaps like
- to choose a different (process-dependent) name. You also could fetch
- the "digest" from somewhere else (i.e. using a conventional random
- number generator).
-
- --
- ARK, 30/May/2000
-
-
- ============================= Archive contents =============================
-
- Original Packed Ratio Date Time Name
- -------- ------- ----- --------- -------- -------------
- 459 254 44.6% 30-May-00 15:49:28 +main.c
- 2082 1021 50.9% 30-May-00 15:45:04 +MD5Random.readme
- 13836 8982 35.0% 30-May-00 15:49:30 +random
- 9932 3577 63.9% 30-May-00 15:39:30 +random.c
- 34830 16782 51.8% 30-May-00 15:50:06 +random.elf
- 831 383 53.9% 30-May-00 15:48:06 +random.info
- 233 155 33.4% 30-May-00 15:36:06 +SCOPTIONS
- 234 118 49.5% 30-May-00 15:23:38 +smakefile
- 200 103 48.5% 30-May-00 15:45:28 +smakefile68k
- -------- ------- ----- --------- --------
- 62637 31375 49.9% 31-May-100 18:45:22 9 files
-